﻿<local:BaseWindow x:Class="Faz.SideWinderSC.Client.ConfigurationWindow"
                  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                  xmlns:local="clr-namespace:Faz.SideWinderSC.Client"
                  xmlns:vm="clr-namespace:Faz.SideWinderSC.Client.ViewModel"
                  Title="Configuration"
                  Height="600"
                  Width="800"
                  MinHeight="400"
                  MinWidth="600"
                  WindowStartupLocation="CenterScreen"
                  Style="{StaticResource WindowStyle}">

    <local:BaseWindow.Resources>
        <BooleanToVisibilityConverter x:Key="VisibilityConverter" />
        <local:ConsoleKeyToKeyConverter x:Key="ConsoleKeyToKeyConverter" />
    </local:BaseWindow.Resources>

    <local:BaseWindow.CommandBindings>
        <CommandBinding Command="{x:Static local:Commands.Start}"
                        Executed="OnStartExecuted" />
    </local:BaseWindow.CommandBindings>

    <DockPanel>

        <!-- The configurable controller models -->
        <ListBox x:Name="models"
                 DockPanel.Dock="Top"
                 Style="{StaticResource Header1ListStyle}"
                 SelectionMode="Single"
                 ItemsSource="{Binding Path=Models}"
                 SelectedIndex="0" />

        <!-- Footer -->
        <DockPanel DockPanel.Dock="Bottom">
            <!-- Start Action -->
            <Button DockPanel.Dock="Right"
                    Style="{StaticResource ImageButtonStyle}"
                    Command="{x:Static local:Commands.Start}">
                <Image Source="Images/next.png"
                       Stretch="None" />
            </Button>

            <!-- Status -->
            <StackPanel Orientation="Vertical">
                <TextBlock>Profile1: xxx</TextBlock>
                <TextBlock>Profile2: xxx</TextBlock>
                <TextBlock>Profile3: xxx</TextBlock>
            </StackPanel>
        </DockPanel>

        <!-- Configuration for the selected model -->
        <DockPanel DataContext="{Binding ElementName=models, Path=SelectedItem}">

            <!-- Profiles -->
            <ListView x:Name="profiles"
                      DockPanel.Dock="Left"
                      Width="190"
                      ItemsSource="{Binding Path=Profiles}"
                      Style="{StaticResource ProfileListStyle}"
                      SelectionMode="Single"
                      SelectedIndex="0">
                <ListView.ItemTemplate>
                    <DataTemplate>
                        <StackPanel Orientation="Horizontal">
                            <TextBlock x:Name="name"
                                       Text="{Binding Path=Name}" />
                            <TextBlock Text="*"
                                       FontWeight="Bold"
                                       Visibility="{Binding Path=IsModified, Converter={StaticResource VisibilityConverter}}" />
                        </StackPanel>
                        <DataTemplate.Triggers>
                            <DataTrigger Binding="{Binding Path=IsModified}"
                                         Value="True">
                                <Setter TargetName="name"
                                        Property="FontWeight"
                                        Value="Bold" />
                            </DataTrigger>
                        </DataTemplate.Triggers>
                    </DataTemplate>
                </ListView.ItemTemplate>
            </ListView>

            <!-- Controller Display
            <Label DockPanel.Dock="Left">
                <local:SwscView />
            </Label> -->

            <!-- Current Mapping Editor -->
            <Grid DockPanel.Dock="Bottom"
                  DataContext="{Binding ElementName=mappings, Path=SelectedItem}">
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="Auto" />
                    <ColumnDefinition Width="*" />
                </Grid.ColumnDefinitions>
                <Grid.RowDefinitions>
                    <RowDefinition />
                    <RowDefinition />
                </Grid.RowDefinitions>
                <TextBlock Grid.Row="0"
                           Grid.Column="0"
                           VerticalAlignment="Center"
                           Margin="5"
                           Text="Action name" />
                <TextBox Grid.Row="0"
                         Grid.Column="1"
                         Margin="5"
                         Text="{Binding Path=Name, Mode=TwoWay}" />
                <TextBlock Grid.Row="1"
                           Grid.Column="0"
                           VerticalAlignment="Center"
                           Margin="5"
                           Text="Command" />
                <local:KeyBox Grid.Row="1"
                              Grid.Column="1"
                              Margin="5"
                              Mode="OneKey"
                              Keys="{Binding Path=Keys, Mode=TwoWay, Converter={StaticResource ConsoleKeyToKeyConverter}}" />
            </Grid>

            <!-- Mappings -->
            <!--<ListView DockPanel.Dock="Top"
                      DataContext="{Binding ElementName=profiles, Path=SelectedItem}"
                      ItemsSource="{Binding Path=Mappings}">
                <ListView.View>
                    <GridView>
                        <GridViewColumn Header="Button"
                                        DisplayMemberBinding="{Binding Path=Button}" />
                        <GridViewColumn Header="ActionName"
                                        DisplayMemberBinding="{Binding Path=ActionName}" />
                        <GridViewColumn Header="PressedKey"
                                        DisplayMemberBinding="{Binding Path=PressedKey, Converter={StaticResource KeyConverter}}" />
                    </GridView>
                </ListView.View>
            </ListView>-->

            <Grid DataContext="{Binding ElementName=profiles, Path=SelectedItem}">
                <Grid.Resources>
                    <CollectionViewSource x:Key="groupedMappings"
                                          Source="{Binding Path=Mappings}">
                        <CollectionViewSource.GroupDescriptions>
                            <PropertyGroupDescription PropertyName="Button" />
                        </CollectionViewSource.GroupDescriptions>
                    </CollectionViewSource>
                </Grid.Resources>
                <ListBox x:Name="mappings"
                         ItemsSource="{Binding Source={StaticResource groupedMappings}}"
                         Style="{StaticResource MappingListStyle}"
                         ItemTemplate="{StaticResource MappingDataTemplate}"
                         SelectionMode="Single">
                    <ListBox.GroupStyle>
                        <GroupStyle ContainerStyle="{StaticResource MappingGroupItemStyle}">
                            <GroupStyle.Panel>
                                <ItemsPanelTemplate>
                                    <WrapPanel Orientation="Horizontal"
                                               IsItemsHost="True" />
                                </ItemsPanelTemplate>
                            </GroupStyle.Panel>
                        </GroupStyle>
                    </ListBox.GroupStyle>
                </ListBox>
            </Grid>
        </DockPanel>
    </DockPanel>
</local:BaseWindow>
